<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>用户管理</title>

    <script src="/assets/js/config.js"></script>
    <link rel="stylesheet" type="text/css" href="css/apply.css"/>


    <script type="text/javascript" src="js/design.js"></script>
    <script type="text/javascript" src="js/multiSelect.js"></script>
</head>
<body>
<form id="fm">
    <h2 align=" center" id="title">酒水领用单</h2>
    <p>领用日期： <span id="crtDate"></span></p>
    <table border="1" style="border-collapse: collapse;width: 100%">
        <tr>
            <td>领用部门</td>
            <td colspan="4"><input class="layui-input" name="department"></td>

        </tr>
        <tr>
            <td>用途</td>
            <td colspan="5"><input class="layui-input" name="reason"></td>
        </tr>
        <tr>
            <td>领用人</td>
            <td colspan="4"><input class="layui-input" name="userName"></td>
        </tr>
        <tr>
            <td>品名</td>
            <td>单位</td>
            <td>需用</td>
            <td>退还</td>
            <td>实际发放</td>
        </tr>
        <tr>
            <td><input class="layui-input" name="name1"></td>
            <td><input class="layui-input" name="unit1"></td>
            <td><input class="layui-input" name="need1"></td>
            <td><input class="layui-input" name="back1"></td>
            <td><input class="layui-input" name="real1"></td>
        </tr>
        <tr>
            <td><input class="layui-input" name="name2"></td>
            <td><input class="layui-input" name="unit2"></td>
            <td><input class="layui-input" name="need2"></td>
            <td><input class="layui-input" name="back2"></td>
            <td><input class="layui-input" name="real2"></td>
        </tr>
        <tr>
            <td><input class="layui-input" name="name3"></td>
            <td><input class="layui-input" name="unit3"></td>
            <td><input class="layui-input" name="need3"></td>
            <td><input class="layui-input" name="back3"></td>
            <td><input class="layui-input" name="real3"></td>
        </tr>
    </table>
</form>

</body>
<script>
    $(function () {
        var id = getUrlParam();
        if (id) {
            //审批进入
            $("input").prop('readonly', true);
            $("#app").hide();
            $(".layui-layer-btn").hide();
            $.post('/office/flowStepInstance/queryDetail', {id: id}, function (res) {
                if (res.code == 200) {
                    var data = res.obj;
                    $("#crtDate").text(formatDate(new Date(data.crtDate)));
                    drawForm(data, $("#fm"));
                    var goods = JSON.parse(data.goods);
                    for (var i = 0; i < goods.length; i++) {
                        var each = goods[i]
                        $(`[name='name${i + 1}']`).val(each.name);
                        $(`[name='unit${i + 1}']`).val(each.unit);
                        $(`[name='need${i + 1}']`).val(each.need);
                        $(`[name='back${i + 1}']`).val(each.back);
                        $(`[name='real${i + 1}']`).val(each.real);
                    }
                }
            })
            drawApprove(id);
        } else {
            drawAdd();
            var html = ' <button onclick="addExecute()">添加执行人</button>';
            $(html).appendTo("#designButtonList");
            var today = formatDate(new Date())
            $("#crtDate").text(today);
            $("[name='userName']").val(getUserName());
            $("[name='department']").val(getOrgName());
            $.post('/office/flowStepTemplate/getTemplateStep', {userId: getUserId(), templateId: 3}, function (res) {
                if (res.code == 200) {
                    if (res.obj) {
                        drawFlowStep(res.obj.flowNodes);
                    }
                }
            })
        }
    });

    function submitForm() {
        layer.confirm('确认提交', function (index) {
            var param = getSubmitParam();
            let array = [];
            let count = 0;
            $("tr").each(function (i, obj) {
                count = i + 1;
            });
            count = count - 4;
            for (var i = 1; i <= count; i++) {
                var drinkItem = {};
                drinkItem.name = $(`[name='name${i}']`).val();
                drinkItem.unit = $(`[name='unit${i}']`).val();
                drinkItem.need = $(`[name='need${i}']`).val();
                drinkItem.back = $(`[name='back${i}']`).val();
                drinkItem.real = $(`[name='real${i}']`).val();
                array.push(drinkItem);
            }
            param.goods = array;
            param.title = $("#title").text();
            param.approveList = $("#approveList").val();
            param.userId = localStorage.getItem("userId");
            doSubmit('/office/flowWork/addDrinkFlow', param, true);
        })
    }

</script>

</html>